package edu.cmu.cs.stage3.alice.authoringtool.util;

import edu.cmu.cs.stage3.util.Criterion;

/**
 * @author Jason Pratt
 */
public class InAppropriateObjectArrayPropertyCriterion implements Criterion {
	public boolean accept( Object object ) {
		if( object instanceof edu.cmu.cs.stage3.alice.core.Element ) {
			edu.cmu.cs.stage3.alice.core.Element element = (edu.cmu.cs.stage3.alice.core.Element)object;
			edu.cmu.cs.stage3.alice.core.Element parent = element.getParent();

			if( parent != null ) {
				edu.cmu.cs.stage3.alice.core.property.ObjectArrayProperty oap = null;
				if( element instanceof edu.cmu.cs.stage3.alice.core.Transformable ) {
					if( parent instanceof edu.cmu.cs.stage3.alice.core.Transformable ) {
						oap = ((edu.cmu.cs.stage3.alice.core.Transformable)parent).parts;
					}
				} else if( element instanceof edu.cmu.cs.stage3.alice.core.Response ) {
					if( parent instanceof edu.cmu.cs.stage3.alice.core.Sandbox ) {
						oap = ((edu.cmu.cs.stage3.alice.core.Sandbox)parent).responses;
					}
				} else if( element instanceof edu.cmu.cs.stage3.alice.core.Behavior ) {
					if( parent instanceof edu.cmu.cs.stage3.alice.core.Sandbox ) {
						oap = ((edu.cmu.cs.stage3.alice.core.Sandbox)parent).behaviors;
					}
				} else if( element instanceof edu.cmu.cs.stage3.alice.core.Variable ) {
					if( parent instanceof edu.cmu.cs.stage3.alice.core.Sandbox ) {
						oap = ((edu.cmu.cs.stage3.alice.core.Sandbox)parent).variables;
					}
				} else if( element instanceof edu.cmu.cs.stage3.alice.core.Question ) {
					if( parent instanceof edu.cmu.cs.stage3.alice.core.Sandbox ) {
						oap = ((edu.cmu.cs.stage3.alice.core.Sandbox)parent).questions;
					}
				}
				if( oap != null ) {
					return oap.contains( element );
				}
			}
		}

		return true;
	}
}